package com.ylstm.service.impl;

import com.ylstm.mapper.CustomerMapper;
import com.ylstm.pojo.Customer;
import com.ylstm.service.CustomerService;
import com.ylstm.utils.ResultMessage;
import jdk.jfr.internal.EventWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CustomerServiceImpl
 * @Description TODO
 * @date 2022/8/3 10:14
 * @Version 1.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    CustomerMapper customerMapper;
    /*查询所有会员*/
    @Override
    public ResultMessage selectAllVip() {
        List<Customer> viPList = customerMapper.selectAllVip();
        ResultMessage resultMessage = new ResultMessage();
        if (viPList!=null){
            resultMessage.setData(viPList);
            return resultMessage;
        }
        return null;
    }

    /*删除会员*/
    @Override
    public ResultMessage deleteVip(Integer id) {
        int result = customerMapper.deleteVip(id);
        ResultMessage resultMessage = new ResultMessage();
        if (result > 0){
            resultMessage.setCode(222);
        }else {
            resultMessage.setCode(233);
        }
        return resultMessage;
    }
    /*查询单个会员*/
    @Override
    public ResultMessage selectOneVip(Integer id) {
        Customer customer = customerMapper.selectOneVip(id);
        ResultMessage resultMessage = new ResultMessage();
        if (customer != null){
            resultMessage.setData(customer);
            return resultMessage;
        }
       return null;
    }
    /*增加修改会员信息*/
    @Override
    public ResultMessage editorVip(Customer customer) {
        ResultMessage resultMessage = new ResultMessage();
        if (customer.getU_id() != null){
            int resu = customerMapper.updateVip(customer);
            if (resu > 0){
                resultMessage.setCode(222);
            }else {
                resultMessage.setCode(233);
            }
        }else {
            int res = customerMapper.insertVip(customer);
            if (res > 0){
                resultMessage.setCode(222);
            }else {
                resultMessage.setCode(233);
            }
        }
        return resultMessage;
    }
    /*模糊查询用户信息*/
    @Override
    public ResultMessage searchVip(String code) {
        List<Customer> customerList = customerMapper.searchVip(code);
        ResultMessage resultMessage = new ResultMessage();
        if (customerList != null){
            resultMessage.setData(customerList);
        }
        return resultMessage;
    }
}
